<template>
	<view class="main animated fadeIn faster">
		<TitleBarVue :title="title"/>
		<view class="" style="width: 100%; background-color: f4f5fa;">
			<view class="list list-mt-100">
				<view class="item" @click="gotoRealName">
					<text>实名认证</text>
					<view class="icon">
						<text>{{$store.state.user.realName?"已认证":"未认证"}}</text>
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%202457.png"></image>
					</view>
				</view>
				<view class="item" @click="gotoUserAgreement">
					<text>用户协议</text>
					<view class="icon">
						<!-- <text>未签订</text> -->
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%202457.png"></image>
					</view>
				</view>
			</view>
			<view class="list">
				<view class="item" @click="gotoPrivacyPolicy">
					<text>隐私政策</text>
					<view class="icon">
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%202457.png"></image>
					</view>
				</view>
				<!-- <view class="item">
					<text>隐私政策摘要</text>
					<view class="icon">
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%202457.png"></image>
					</view>
				</view> -->
				<view class="item" @click="gotoPersonalInfoList">
					<text>个人信息收集清单</text>
				</view>
				<view class="item" @click="toPolicy">
					<text>未成年人保护计划</text>
					<view class="icon">
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%202457.png"></image>
					</view>
				</view>
				<view class="item" @click="gotoSharedList">
					<text>第三方信息共享清单</text>
					<view class="icon">
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%202457.png"></image>
					</view>
				</view>
				<view class="item" @click="gotoSupperPlayerAgreement">
					<text>超级尊贵玩家服务协议</text>
					<view class="icon">
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%202457.png"></image>
					</view>
				</view>
				<view class="item" @click="gotoContinuousSubScriptionAgreement">
					<text>连续订阅服务协议</text>
					<view class="icon">
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%202457.png"></image>
					</view>
				</view>
			</view>
			<view class="list clearCache mt-2">
				<view class="item d-flex-middle" style="padding: 20rpx 0;">
					<text>接收消息通知</text>
					<switch checked="true" color="#e8b2dc" style="transform:scale(0.7)"/>
				</view>
			</view>
			<view class="list clearCache mt-2">
				<view class="item d-flex-middle" style="padding: 20rpx 0;">
					<text>接收搭子推荐通知</text>
					<switch :checked="$store.state.isRecomend" @change="switchChange" color="#e8b2dc" style="transform:scale(0.7)"/>
				</view>
			</view>
			<view class="list clearCache mt-2">
				<view class="item" @click="OpenClearCachePopup">
					<text>清除缓存</text>
					<view class="icon">
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%202457.png"></image>
					</view>
				</view>
			</view>
			<view class="list clearCache mt-2" @click="logout">
				<view class="item">
					<text>退出登录</text>
					<view class="icon">
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%202457.png"></image>
					</view>
				</view>
			</view>
			<view class="list clearCache mt-2" @click="disappear">
				<view class="item">
					<text>注销账号</text>
					<view class="icon">
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%202457.png"></image>
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="ClearCachePopup" background-color="#fff" border-radius="8px 8px 8px 8px">
			<view class="popup-content changeNike" :class="{ 'popup-height': type === 'left' || type === 'right' }" style="height: 280rpx; width: 500rpx;">
				<view class="text-center font32">清除缓存</view>
				<view class="mt-2">根据缓存文件的大小，清理时间从几秒到几分钟不等，请耐心等待</view>
				<view class="btn d-flex position-absolute">
					<view class="cancle text-center font28" style="width: 50%; line-height: 90rpx; border-right: 1px solid #ededed;" @click="ColseClearCachePopup">取消</view>
					<view class="confirm text-center font28" style="width: 50%; line-height: 90rpx;" @click="ClearCache">确认</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import TitleBarVue from '../../components/TitleBar.vue';
	import store from '@/store/index.js';
	import { userApi } from '../../http/userApi';
	export default {
		data() {
			return {
				display: "none;",
				bgcolor: "#fff",
				title: '设置'
			}
		},
		components: {TitleBarVue},
		methods: {
			switchChange: function(event) {
				console.log('event.detail.value',event.detail.value)
				store.commit('setHotRecommend',event.detail.value)
				console.log('$store.state.isHot',store.state.isHot)
			},
			async logoutUser(){
				let res=await userApi.logout();
			},
			async editAccount(){
				let param={accountStatus:2};
				let res=await userApi.editAccount(param);
			},
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			gotoSharedList() {
				uni.navigateTo({
					url: '/pagesMain/SharedLList/SharedLList'
				})
			},
			toPolicy(){
				uni.navigateTo({
					url: '/pagesApp/MinorProtectionPlan/MinorProtectionPlan'
				})	
			},
			gotoPersonalInfoList() {
				uni.navigateTo({
					url: '/pagesMain/PersonalInformationList/PersonalInformationList'
				})
			},
			gotoPrivacyPolicy() {
				uni.navigateTo({
					url:'/pagesMain/privacy/privacy?type=1'
					// url: '/pagesMain/PrivacyPolicy/PrivacyPolicy'
				})
			},
			gotoUserAgreement() {
				uni.navigateTo({
					url:'/pagesMain/privacy/privacy?type=2'
					// url: '/pagesMain/UserAgreement/UserAgreement'
				})
			},
			gotoRealName() {
				uni.navigateTo({
					url: '/pagesApp/RealName/RealName'
				})	
			},
			gotoSupperPlayerAgreement() {
				uni.navigateTo({
					url: '/pagesApp/SuperPlayerAgreement/SuperPlayerAgreement'
				})
			},
			gotoContinuousSubScriptionAgreement() {
				uni.navigateTo({
					url: '/pagesApp/ContinuousSubscriptionAgreement/ContinuousSubscriptionAgreement'
				})
			},
			ClearCache(type) {
				uni.getStorageInfo({
					success: function (res) {
						res.keys.forEach(i => {
							if(i !== 'u_token') {
								uni.removeStorage({
									key: i
								});
							}
						})
						uni.showToast({
							icon: 'none',
							title:'清除成功！',
							duration:1500
						})
					}
				});
				this.ColseClearCachePopup()
			},
			OpenClearCachePopup(type) {
				this.type = type
				this.$refs.ClearCachePopup.open(type)
			},
			ColseClearCachePopup() {
				this.$refs.ClearCachePopup.close()
			},
			logout(){
				uni.showModal({
				  content: '确认需要退出登录吗？',
				  success: (res) => {
				    if (res.confirm) {
					// this.logoutUser();
				     this.$tim.logout().then(imResponse => {
				     	console.log('登出成功:', imResponse);
				     })
					 store.commit("logOut")
					 uni.redirectTo({
					 	url:'/pagesMain/mplogin/mplogin'
					 })					  
				    } else if (res.cancel) {
											 
				      // console.log('用户点击取消');
				      // 不执行任何操作，用户取消退出
				    }
				  }
				});
				
			},
			disappear(){
				this.$tim.logout().then(imResponse => {
					console.log('注销账号:', imResponse);
				})
				store.commit("logOut")
				uni.showToast({
					icon: 'none',
					title:'账号注销成功！',
					duration:1500,
					complete() {
						setTimeout(()=>{
							uni.navigateTo({
								url:'/pagesMain/mplogin/mplogin'
							})
						},1500)
					}
				})
			

				
			},
			disappear(){
					uni.navigateTo({
									url: '/pagesApp/logout/logout'
								})
				
			}
		}
	}
</script>

<style scoped lang="scss">
.main {
	background: #f4f5fa;
	overflow: hidden;
	.content {
		width: 100%;
		overflow: hidden;
	}
	.list {
		width: 100%;
		background-color: #ffffff;
		.item {
			display: flex;
			justify-content: space-between;
			padding: 30rpx 0;
			border-bottom: 1px solid rgba(204, 204, 204, .2);
			text {
			margin-left: 30rpx;
				font-size: 28rpx;
				color: #555;
			}
			.icon {
				image {
					margin: 0 30rpx 8rpx 12rpx;
					width: 10rpx;
					height: 20rpx;
					transform: rotate(180deg);
				}
				text {
					font-size: 26rpx;
				}
			}
		}
	}
	.clearCache {
		.item {
			border: 0;
		}
	}
}
.changeNike {
	padding: 40rpx 60rpx 0;
	color: #1f1f1f;
	.btn {
		bottom: 0;
		left: 0;
		width: 100%;
		height: 90rpx;
		border-top: 1px solid #ededed;
	}
	.cancle {
		color: #9E9D9D;
	}
	.confirm {
		color: #66CCCC;
	}
}
.pt-300 {
	padding-top: 300rpx;
}
.list-mt-100 {
	margin: 170rpx 0rpx 20rpx !important;
}
</style>
